home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / sio.1.5.6 / suite / tester < prev    next >
Encoding:
Text File  |  1992-12-09  |  3.5 KB  |  167 lines

  1. #!/bin/sh
  2.  
  3. # (c) Copyright 1992 by Panagiotis Tsirigotis
  4. # All rights reserved.  The file named COPYRIGHT specifies the terms 
  5. # and conditions for redistribution.
  6.  
  7.  
  8. #
  9. # $Id: tester,v 7.1 1992/06/01 21:38:57 panos Exp $
  10. #
  11.  
  12. #
  13. # Usage:
  14. #            tester function-name function-name ...
  15. # or
  16. #            tester all
  17. #
  18. # function-name is that name of a sio function (or macro)
  19. #
  20.  
  21. copy_file=/usr/dict/words
  22. temp_file=/tmp/w
  23. make_log=MAKE.LOG
  24.  
  25. trap_function()
  26. {
  27.     rm -f $temp_file $make_log
  28.     echo
  29.     exit 1
  30. }
  31.  
  32.  
  33. make_program()
  34. {
  35.     target=$1
  36.     cflags="$2"
  37.     if test -f $1 -a ! -x $1 ; then rm -f $1 ; fi
  38.     if test "$cflags"
  39.     then
  40.         make -s "$cflags" $target >$make_log 2>&1
  41.     else
  42.         make -s $target >$make_log 2>&1
  43.     fi
  44.     exit_code=$?
  45.     if test $exit_code -eq 0 -a -x $1
  46.     then
  47.         rm -f $make_log
  48.     else
  49.         echo "FAILED"
  50.         echo "   The make failed. Check the make log file << $make_log >>"
  51.         exit
  52.     fi
  53. }
  54.  
  55.  
  56.  
  57. #
  58. # test_function expects a single argument, the name of the function
  59. # it will test.
  60. # It creates a program that has the name of the function by invoking
  61. # make with the symbol -DTEST_<function_name>
  62. # Before it invokes make, it checks if there is a file with the
  63. # function name, and if it exists and it is not executable, it
  64. # removes it. The reason is that the SunOS ld will create a target
  65. # file with the x bit not set if the linking fails.
  66. #
  67. test_function()
  68. {
  69.     expression="echo $"$1
  70.     var=`eval $expression`
  71.     if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  72.  
  73.     echo -n "TESTING $1 "
  74.     make_program $1 "CFLAGS=-g -DTEST_$1"
  75.  
  76.     ./$1 < $copy_file >$temp_file
  77.     exit_code=$?
  78.     if test $exit_code -ne 0
  79.     then
  80.         echo "FAILED"
  81.         echo "   Test program exited with exit code $exit_code"
  82.         echo "   Temporary file << $temp_file >> not deleted"
  83.         exit
  84.     fi
  85.     cmp -s $copy_file $temp_file
  86.     if test $? -ne 0
  87.     then
  88.         echo "FAILED"
  89.         echo "   The files << $copy_file >> and << $temp_file >> are not the same"
  90.         exit
  91.     else
  92.         echo PASSED
  93.     fi
  94.     rm -f $temp_file
  95. }
  96.  
  97.  
  98. test_sprint()
  99. {
  100.     var=$Sprint
  101.     program=Sprint
  102.     if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  103.  
  104.     echo TESTING Sprint
  105.     if test -f $program -a ! -x $program ; then rm -f $program ; fi
  106.     make_program $program ""
  107.     $TESTSHELL sprint_test
  108. }
  109.  
  110.  
  111. trap trap_function 1 2 3 15
  112.  
  113. #
  114. # There is a variable for every function to be tester. That variable
  115. # can have the values "yes" or "".
  116. # When a function is specified, it takes the value of $run. Initially $run 
  117. # is "yes", so a specified function has its variable set to "yes". 
  118. # If "all" is specified, $run becomes "no", so subsequently specified
  119. # functions, have their variables set to "no".
  120. #
  121. # We test a function iff:
  122. #        its variable is "yes" OR its variable is "" and $all is "yes"
  123. # We don't test a function iff:
  124. #        its variable is "no" OR its variable is "" and $all is "no"
  125. #        
  126. # Therefore, all functions specified after "all" will NOT be tested.
  127. #
  128. run=yes
  129. all=no
  130.  
  131. while test $# -gt 0
  132. do
  133.     case $1 in
  134.         Sputchar)    Sputchar=$run ;;
  135.         Sgetchar)    Sgetchar=$run ;;
  136.         Srdline)        Srdline=$run ;;
  137.         Sfetch)        Sfetch=$run ;;
  138.         Sread)        Sread=$run ;;
  139.         Swrite)        Swrite=$run ;;
  140.         Sgetc)        Sgetc=$run ;;
  141.         Sputc)        Sputc=$run ;;
  142.         Sflush)        Sflush=$run ;;
  143.         Sundo)        Sundo=$run ;;
  144.         Sprint)        Sprint=$run ;;
  145.         switch)        switch=$run ;;
  146.         switch2)        switch2=$run ;;
  147.         all)            all=yes ; run="no" ;;
  148.         *) echo Bad argument: $1
  149.     esac
  150.     shift
  151. done
  152.  
  153. test_function Sgetchar
  154. test_function Sputchar
  155. test_function Sread
  156. test_function Swrite
  157. test_function Srdline
  158. test_function Sfetch
  159. test_function Sgetc
  160. test_function Sputc
  161. test_function Sflush
  162. test_function Sundo
  163. test_function switch
  164. test_function switch2
  165. test_sprint
  166.  
  167.